<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	template="/facelets/template.xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">


	<ui:define name="title">#{x['faces.title.label.user.search']}</ui:define>

	<ui:define name="menu">
		<ui:include src="userMenu.xhtml" />
	</ui:define>

	<ui:define name="content">

		<h:form id="userSearchForm" prependId="false">

			<p:growl id="msgs" showDetail="true" showSummary="false"
				autoUpdate="true" />

			<p:panel id="userSearchPanel">

				<p:focus for="usernameId" />
				<p:spacer height="12px" />

				<h:panelGrid id="userSearchPanelGrid" columns="5" cellpadding="5">
					<h:outputLabel for="usernameId"
						value="#{x['faces.label.field.username.user.registry']}: " />
					<p:inputText id="usernameId" value="#{userManager.username}" />

					<h:outputLabel for="nameId"
						value="#{x['faces.label.field.firstname.user.registry']}: " />
					<p:inputText id="nameId" value="#{userManager.name}" />

					<p:commandButton id="searchId" action="#{userManager.search()}"
						update="userTableId" icon="ui-icon ui-icon-search"
						title="Pesquisar"
						value="#{x['faces.button.label.generic.search.action']}"
						process="userSearchPanelGrid">
					</p:commandButton>
				</h:panelGrid>

				<p:spacer height="12px" />

				<p:dataTable id="userTableId" var="user"
					value="#{userManager.users}" paginator="true" rows="7"
					style="width:695px">

					<p:column>
						<f:facet name="header">
							<h:outputText
								value="#{x['faces.label.field.username.user.registry']}" />
						</f:facet>
						<h:outputLabel value="#{user.username}" />
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText
								value="#{x['faces.label.field.firstname.user.registry']}" />
						</f:facet>
						<h:outputLabel value="#{user.name}" />
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText value="#{x['faces.label.profile']}" />
						</f:facet>
						<h:outputLabel value="#{user.profile.name}" />
					</p:column>

					<p:column style="width:70px">
						<f:facet name="header">
							<h:outputText value="#{x['faces.label.generic.action']}" />
						</f:facet>

						<p:commandButton id="editButton" icon="ui-icon ui-icon-pencil"
							title="#{x['faces.button.generic.edit']}" oncomplete="dlg.show()"
							action="#{userManager.edit(user)}" process="@this"
							immediate="true"
							update=":userSearchForm:userPanelId, :userSearchForm:buttonPanelGrid">
							<f:actionListener
								type="br.com.carser.listeners.CleanFormListener" />
						</p:commandButton>

						<p:commandButton id="excludeButton"
							action="#{userManager.delete()}" icon="ui-icon ui-icon-trash"
							title="#{x['faces.button.generic.exclude']}" process="@this"
							update="@form" immediate="true">
							<f:setPropertyActionListener for="excludeButton"
								target="#{userManager.user}" value="#{user}" />
						</p:commandButton>
					</p:column>

				</p:dataTable>

				<h:panelGrid columns="1" cellpadding="5">
					<p:commandButton value="#{x['faces.button.generic.new']}"
						action="#{userManager.reset()}" oncomplete="dlg.show()"
						icon="ui-icon ui-icon-plus" title="Adicionar" process="@this"
						update=":userSearchForm:userPanelId, :userSearchForm:buttonPanelGrid">
						<f:actionListener type="br.com.carser.listeners.CleanFormListener" />
					</p:commandButton>
				</h:panelGrid>
			</p:panel>

			<p:dialog id="userSaveDialog"
				header="#{x['faces.label.dialog.registry']}" widgetVar="dlg"
				resizable="false" modal="true">

				<p:focus for="inputName" />

				<h:panelGrid id="userPanelId" columns="4" cellpadding="5">

					<h:outputLabel
						value="#{x['faces.label.field.firstname.user.registry']}"
						for="nameId" />
					<p:inputText id="inputName"
						requiredMessage="#{x['faces.label.required.firstname.user.registry']}"
						value="#{userManager.user.name}" required="true" />

					<h:outputLabel for="inputEmail"
						value="#{x['faces.label.field.email.user.registry']}: " />
					<p:inputText id="inputEmail" value="#{userManager.email}" />

					<h:outputLabel for="us"
						value="#{x['faces.label.field.username.user.registry']}" />
					<p:inputText id="us"
						requiredMessage="#{x['faces.label.required.username.user.registry']}"
						value="#{userManager.user.username}" required="true" />

					<h:outputLabel for="inputPasswd1"
						value="#{x['faces.label.field.password.user.registry']}" />
					<p:password id="inputPasswd1" value="#{userManager.user.password}"
						match="inputPasswd2" feedback="true" required="true"
						requiredMessage="#{x['faces.label.required.password.user.registry']}"
						validatorMessage="#{x['faces.label.error.password.confirmation']}" />

					<p:tab />
					<p:tab />

					<h:outputLabel for="inputPasswd2"
						value="#{x['faces.label.field.password.confirmation']}: " />
					<p:password id="inputPasswd2" value="#{userManager.user.password}"
						feedback="true" required="true"
						requiredMessage="#{x['faces.label.error.required.password.confirmation']}" />

					<h:outputLabel for="inputCellPhone"
						value="#{x['faces.label.field.user.cellphone.registry']}: " />
					<p:inputMask id="inputCellPhone" value="#{userManager.cellPhone}"
						mask="(99) 9999-9999" />

					<h:outputLabel for="inputHomePhone"
						value="#{x['faces.label.field.user.homephone.registry']}" />
					<p:inputMask id="inputHomePhone" value="#{userManager.homePhone}"
						mask="(99) 9999-9999" />

					<h:outputLabel for="selectProfile"
						value="#{x['faces.label.profile']}: " />

					<p:selectOneMenu id="selectProfile" value="#{userManager.profile}"
						required="true"
						requiredMessage="#{x['faces.input.profile.required.error']}"
						style="width:185px">
						<f:selectItem
							itemLabel="#{x['faces.label.select.menu.default.message']}" />
						<f:selectItems id="profileList" value="#{userManager.profiles}"
							var="profile" itemValue="#{profile}" itemLabel="#{profile.name}" />
					</p:selectOneMenu>

				</h:panelGrid>

				<h:panelGrid id="buttonPanelGrid" columns="6" cellpadding="5">
					<p:commandButton value="#{x['faces.button.label.generic.reset']}"
						type="reset" title="#{x['faces.button.label.generic.reset']}" />
					<p:commandButton type="button" onclick="dlg.hide()"
						value="#{x['faces.button.label.generic.cancel']}"
						title="#{x['faces.button.label.generic.cancel']}"
						rendered="#{!userManager.saved}" />
					<p:commandButton action="#{userManager.save()}"
						rendered="#{!userManager.saved}"
						value="#{x['faces.button.label.generic.save']}"
						title="#{x['faces.button.label.generic.save']}" process="@form"
						update="@this, :userSearchForm:buttonPanelGrid" />
					<p:commandButton type="button" onclick="dlg.hide()"
						value="#{x['faces.button.generic.close']}"
						rendered="#{userManager.saved}" />
				</h:panelGrid>

			</p:dialog>

		</h:form>

	</ui:define>

</ui:composition>